@ECHO OFF

REM // Needs Argument %1 = Version String

REM // save current directory
pushd .

IF %QTDIR%=="" (
  ECHO QTDIR not set. Using C:\Qt\4.8.1 setme in copy_release.bat
  set QTDIR=C:\Qt\4.8.1
)

REM // Get parent directory
for %%? in ("%~dp0..") do set parent=%%~f?

ECHO Copying release files to: %parent%\bin\deploy
IF EXIST %parent%\bin\deploy GOTO copy
MD %parent%\bin\deploy GOTO copy
IF EXIST %parent%\bin\deploy\templates GOTO copy
MD %parent%\bin\deploy\templates

:copy
XCOPY /Y "%parent%\bin\release\PlacesParser.exe" "%parent%\bin\deploy\"
XCOPY /Y "%parent%\templates\*.*" "%parent%\bin\deploy\templates\"
XCOPY /Y "%parent%\PlacesParser\PlacesParser_en.qm "%parent%\bin\deploy\"
XCOPY /Y "%QTDIR%\bin\QtGui4.dll" "%parent%\bin\deploy\"
XCOPY /Y "%QTDIR%\bin\QtCore4.dll" "%parent%\bin\deploy\"
XCOPY /Y "%parent%\lib\sqlite3\debug\sqlite3.dll" "%parent%\bin\deploy\"
XCOPY /Y "%parent%\lib\nss-3.11\lib\*.dll" "%parent%\bin\deploy\"
XCOPY /Y "%parent%\lib\nspr-4.6.1\lib\*.dll" "%parent%\bin\deploy\"

ECHO Creating ZIP Archive
CD %parent%\bin\deploy

IF EXIST "C:\Program Files\7-Zip\7z.exe" (
  "C:\Program Files\7-Zip\7z.exe" a -tzip PlacesParser_%1.zip *.exe *.dll templates\*.*
  GOTO end
)
IF EXIST "C:\Program Files (x86)\7-Zip\7z.exe" (
  "C:\Program Files (x86)\7-Zip\7z.exe" a -tzip PlacesParser_%1.zip *.exe *.dll templates\*.*
  GOTO end
)

ECHO 7zip not found! Trying 7zip from Path:
7z.exe a -tzip PlacesParser_%1.zip *.exe *.dll templates\*.*
IF %ERRORLEVEL% GEQ 1 ECHO 7zip failure. Giving up ...
GOTO end

:end
REM // restore current directory
ECHO Restoring previous directory
popd
